#include <REG51.H> 
//?1???:??adc0808????
/*

*/
#include <adc0808.H> 
unsigned int count = 0;
unsigned char segdata[]={  //????? 
                0x3F,  //"0"
                0x06,  //"1"
                0x5B,  //"2"
                0x4F,  //"3"
                0x66,  //"4"
                0x6D,  //"5"
                0x7D,  //"6"
                0x07,  //"7"
                0x7F,  //"8"
                0x6F  //"9"
								};

void InitTimer0(void)//50ms
{
    TMOD |= 0x01;
    TH0 = 0x3C;
    TL0 = 0x0B0;
    EA = 1;
    ET0 = 1;
    TR0 = 1;
}


void InitUART(void)
{
    TMOD |= 0x20;
    SCON = 0x50;
    TH1 = 0xFD;
    TL1 = TH1;
    PCON = 0x00;
    EA = 1;
    ES = 1;
	  ET1 = 1;
    TR1 = 1;
}

void SendOneByte(unsigned char c)
{
    SBUF = c;
    while(!TI);
    TI = 0;
}

void SendCmd()
{
		SendOneByte(0x55);
		SendOneByte(0xAA);
		SendOneByte(0x01);
		SendOneByte(0x01);
		SendOneByte(dat);
}
 
void Timer0_ISR(void) interrupt 1
{
	TH0 = 0x3C;
  TL0 = 0x0B0;	 
	count++;
	if(count == 20)//
	{
		count = 0;
		
		/*

		*/	
		SendCmd();
	}
}

 
void main()
{
	InitTimer0();  
	InitUART();
	while(1)
	{
		
		/*
		
		*/
		getData();
		if(dat>=0 && dat<1)
			P0=segdata[0];
		else if(dat>=1 && dat<2)
			P0=segdata[1];
		else if(dat>=2 && dat<3)
			P0=segdata[2];
		else if(dat>=3 && dat<4)
			P0=segdata[3];
		else 
			P0=segdata[4];
	}
}
